<?php
require('config.php');

        $user_id=$_REQUEST['user_id'];
        $orderId=$_REQUEST['orderId'];
        $goodsId=$_REQUEST['goodsId'];
        $shopId=$_REQUEST['shopId'];
        $packScore=$_REQUEST['packScore'];
        $timeScore=$_REQUEST['timeScore'];
        $serviceScore=$_REQUEST['serviceScore'];
        $time=date('Y-m-d H:i:s');
		$sql="select * from `".$oto."_goods_appraises` where `userId`='".$user_id."' and orderId='{$orderId}' and goodsId='{$goodsId}' and shopId='{$shopId}'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$appraises_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(!isset($appraises_info))
		{
			$sql="INSERT INTO ".$oto."_goods_appraises (`userId`,`orderId`,`goodsId`,`shopId`,`packScore`,`timeScore`,`serviceScore`,`createTime`) VALUES ('$user_id','$orderId','$goodsId','$shopId','$packScore','$timeScore','$serviceScore','$time')";
            $result=$db->query($sql);
            if($result)
            {
            	$data[0]['pan']=1;
            }
            else
            {
            	$data[0]['pan']=0;
            }
            $sql="select * from ".$oto."_shop_scores where shopId='{$shopId}'";
            $result=$db->query($sql);
            while($row=$result->fetch_assoc()){
                $scores[]=$row;//将取得的所有数据赋值给person_info数组
            }
            if(isset($scores))
            {
                $totalScore=$packScore+$timeScore+$serviceScore;
                $sql="update ".$oto."_shop_scores set totalScore=totalScore+$totalScore,goodsScore=goodsScore+$packScore,timeScore=timeScore+$timeScore,serviceScore=serviceScore+$serviceScore,totalUsers=totalUsers+1,goodsUsers=goodsUsers+1,serviceUsers=serviceUsers+1,timeUsers=timeUsers+1 where shopId='{$shopId}'";
                $result=$db->query($sql);
            }
            else
            {
                $sql="INSERT INTO ".$oto."_shop_scores (`shopId`,`totalScore`,`totalUsers`,`goodsScore`,`goodsUsers`,`serviceScore`,`serviceUsers`,`timeScore`,'timeUsers') VALUES ('$shopId','$totalScore','1','$packScore','1','$serviceScore','1','$timeScore','1')";
                $result=$db->query($sql);
            }
		}
		else
		{
			$sql="update ".$oto."_goods_appraises set packScore='{$packScore}',timeScore='{$timeScore}',serviceScore='{$serviceScore}' where userId='{$user_id}' and orderId='{$orderId}' and goodsId='{$goodsId}' and shopId='{$shopId}'";
			$result=$db->query($sql);
			if($result)
            {
            	$data[0]['pan']=1;
            }
            else
            {
            	$data[0]['pan']=0;
            }
            $sql="select * from ".$oto."_shop_scores where shopId='{$shopId}'";
            $result=$db->query($sql);
            while($row=$result->fetch_assoc()){
                $scores[]=$row;//将取得的所有数据赋值给person_info数组
            }
            if(isset($scores))
            {
                $totalScore=$packScore+$timeScore+$serviceScore;
                $sql="update ".$oto."_shop_scores set totalScore=totalScore+'$totalScore',goodsScore=goodsScore+'$packScore',timeScore=timeScore+'$timeScore',serviceScore=serviceScore+'$serviceScore' where shopId='{$shopId}'";
                $result=$db->query($sql);
            }
            else
            {
                $sql="INSERT INTO ".$oto."_shop_scores (`shopId`,`totalScore`,`totalUsers`,`goodsScore`,`goodsUsers`,`serviceScore`,`serviceUsers`,`timeScore`,'timeUsers') VALUES ('$shopId','$totalScore','1','$packScore','1','$serviceScore','1','$timeScore','1')";
                $result=$db->query($sql);
            }
		}
		echo json_encode($data);
?>